//
//  EXRChooseTpyeCell.m
//  HuiKaoClient
//
//  Created by 龚 杰 on 13-2-25.
//  Copyright (c) 2013年 龚 杰. All rights reserved.
//

#import "EXRChooseTpyeCell.h"

@implementation EXRChooseTpyeCell
@synthesize delegate;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        isChoose = NO;
        m_choose = [UIButton buttonWithType:UIButtonTypeCustom];
        m_choose.frame = CGRectMake(12, 12, 20, 20);
        [m_choose setBackgroundImage:[UIImage imageNamed:@"select.png"] forState:UIControlStateNormal];
        [m_choose addTarget:self action:@selector(changeChoose) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:m_choose];
        [m_choose retain];
        
        m_label = [[UILabel alloc] initWithFrame:CGRectMake(40, 12,self.frame.size.width - 70, 22)];
        m_label.font = [UIFont boldSystemFontOfSize:16.0f];
        m_label.textColor = [UIColor blackColor];
        m_label.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:m_label];
    }
    return self;
}
- (void)changeChoose
{
    NSString* ids = [NSNumber numberWithInt:m_choose.tag].stringValue;
    if (!isChoose) {
        [m_choose setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
        isChoose = YES;
        if (delegate!=nil) {
            
            [delegate getTag:[NSDictionary dictionaryWithObjectsAndKeys:@"YES",@"isChoose",ids,@"id", nil]];
        }
    }else{
        [m_choose setImage:nil forState:UIControlStateNormal];
        isChoose = NO;
        if (delegate!=nil) {
            [delegate getTag:[NSDictionary dictionaryWithObjectsAndKeys:@"NO",@"isChoose",ids,@"id",nil]];
        }
    }

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)initData:(NSString*)name tag:(NSInteger)_tag select:(NSMutableArray*)selectarry
{
    NSString* text = [NSString stringWithFormat:@"%@公务员考试",name];
    m_label.text = text;
    m_choose.tag = _tag;
    BOOL isselect = NO;
    for (NSString* str in selectarry) {
        if (m_choose.tag == str.integerValue) {
            isselect = YES;
        }
    }
    [self setSelectedCell:isselect];
}
- (void)setSelectedCell:(BOOL)is
{
    isChoose = is;
    if (isChoose) {
        [m_choose setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
        
    }else{
        [m_choose setImage:nil forState:UIControlStateNormal];
    }
}
- (void)dealloc
{
    [m_choose release];
    [m_label release];
    [super dealloc];
}
@end
